package cn.huiyunche.admin.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.huiyunche.admin.utils.AdminUtils;
import cn.huiyunche.base.service.interfaces.CWaybillService;
import cn.huiyunche.base.service.model.SysAdminUser;
import cn.huiyunche.base.service.vo.Result;

@Controller
@RequestMapping("/attach")
public class CWaybillAttachController {
	private static final Logger LOGGER = LoggerFactory.getLogger(CWaybillAttachController.class);

	@Autowired
	private CWaybillService cWaybillService = null;

	private CWaybillService getCWaybillService() {
		return this.cWaybillService;
	}

	/**
	 * 上传提车照片
	 * 
	 * @param id
	 *            运单ID
	 * @param attachs
	 *            图片JSON字符串
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/send", method = RequestMethod.POST)
	@ResponseBody
	public Result<Object> send(Long id, String attachs) throws Exception {
		LOGGER.info("send params waybillId: {}, attach: {}", id, attachs);
		SysAdminUser sysAdminUser = AdminUtils.getSysAdminUser();
		Result<Object> result = new Result<Object>(true, null, "上传提车照片成功");
		result.setData(this.getCWaybillService().confirmSend(id, attachs, sysAdminUser));
		return result;
	}

	/**
	 * 上传交车照片
	 * 
	 * @param id
	 *            运单ID
	 * @param attachs
	 *            图片JSON字符串
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/delivery", method = RequestMethod.POST)
	@ResponseBody
	public Result<Object> delivery(Long id, String attachs) throws Exception {
		LOGGER.info("delivery params waybillId: {}, attach: {}", id, attachs);
		SysAdminUser sysAdminUser = AdminUtils.getSysAdminUser();
		Result<Object> result = new Result<Object>(true, null, "上传交车照片成功");
		result.setData(this.getCWaybillService().confirmDliver(id, attachs, sysAdminUser));
		return result;
	}
}
